package com.icss.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.icss.dao.ReviewBeanDao;
import com.icss.dao.reviewClassDao;
import com.icss.dao.reviewDao;
import com.icss.entity.Custom;
import com.icss.entity.Review;
import com.icss.entity.ReviewBean;
import com.icss.entity.ReviewClass;
@Controller
public class reviewController {
	@Autowired
	private reviewDao dao;
	@Autowired
	private ReviewBeanDao rbdao;
	@Autowired
	private reviewClassDao rcdao;

	@RequestMapping("review") 
	public String excute(Model model,Review review) {
		System.out.println("001");
		List<ReviewBean> list=rbdao.findAll(review);
		List<ReviewClass> rclist=rcdao.findAllClass();
		model.addAttribute("reviewclass",rclist);
		model.addAttribute("review",list);
		return "background/reviewManage";
	}
	@RequestMapping("reviewDele") 
	public String deleReview(Integer c_reviewid) {
		System.out.println("删除"+c_reviewid);
		int r=dao.deleReview(c_reviewid);
		if (r>0) {
			return "redirect:/review.do";
		}
		else {
			return "background/reviewManage";
		}
	}
	@RequestMapping("findByCId") 
	public String findByCId(Integer c_id,Model model,HttpServletRequest request) {
		HttpSession session=request.getSession();
		Custom custom=(Custom) session.getAttribute("custom");
		c_id=custom.getC_id();
		System.out.println("查看"+c_id);
		List<ReviewBean> beans=rbdao.findByCId(c_id);
		model.addAttribute("review",beans);
		return "MyreviewManage";
	}
}
